package cn.xwj.mongoDBtest;

import com.mongodb.MongoClient;
import com.mongodb.client.MongoDatabase;

/**
 * Created by thinkjoy on 2017/6/16.
 * MongoDB数据库连接
 */
public class MongoDBCon {
    private static MongoClient mongoClient;
    private static MongoDatabase mongoDatabase;
    public static MongoDatabase MongoDBConInstence() {
        try {
            mongoClient=new MongoClient("localhost",27017);
            mongoDatabase=mongoClient.getDatabase("xuweijie");
            System.out.println("MondoDB数据库连接成功");
            return mongoDatabase;
        }catch (Exception e){
            e.printStackTrace();
            System.out.println("MondoDB数据库连接失败");
            return null;
        }
    }
}
